Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New mappers added: LowerCaseMapper and UpperCaseMapper #927

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

andrey-helldar
Copy link
Contributor

In some projects there was a need to use such mappers and I created them in the application. Then I thought that they could be added to the package. Hope this helps :)

I also added information about available mappers with usage examples to the documentation page.

image

Copy link
Member

@rubenvanassche rubenvanassche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small changes, after that, ready for merge!

Comment on lines 84 to 115
### Available mappers:

```php
class ContractData extends Data
{
public function __construct(
#[MapName(CamelCaseMapper::class)]
public string $name,
#[MapName(SnakeCaseMapper::class)]
public string $recordCompany,
#[MapName(new ProvidedNameMapper('country field'))]
public string $country,
#[MapName(StudlyCaseMapper::class)]
public string $cityName,
#[MapName(LowerCaseMapper::class)]
public string $addressLine1,
#[MapName(UpperCaseMapper::class)]
public string $addressLine2,
) {
}
}
```
```php
[
'name' => 'Rick Astley',
'record_company' => 'RCA Records',
'country field' => 'Belgium',
'CityName' => 'Antwerp',
'addressline1' => 'some address line 1',
'ADDRESSLINE2' => 'some address line 2',
]
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can do it

Copy link
Contributor Author

@andrey-helldar andrey-helldar Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I decided to also add a link to the documentation page https://github.com/spatie/laravel-data/blob/main/docs/as-a-resource/mapping-property-names.md as it directly applies to it
  2. I hope I have correctly specified the page weight for the menu sorting.
  3. I don't know how correctly Google Translate translated the sentence into English.

@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not add strict types to Spatie packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. My file templates use strict mode by default.

I'll remove that.

@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not add strict types to Spatie packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@rubenvanassche
Copy link
Member

Thanks!

@rubenvanassche rubenvanassche merged commit bd7b609 into spatie:main Jan 23, 2025
12 checks passed
@andrey-helldar andrey-helldar deleted the patch/2025-01-10/19-55 branch January 23, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants